package nc.ui.cad.task;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import nc.ui.pub.beans.UIRefPane;
import nc.ui.pub.beans.ValueChangedEvent;
import nc.ui.pub.beans.ValueChangedListener;
import nc.ui.trade.card.BillCardUI;

public class DeptEventHandler implements ItemListener, ValueChangedListener {
	private BillCardUI m_billUI = null;

	public DeptEventHandler(BillCardUI billUI) {
		super();
		this.m_billUI = billUI;
	}

	public void itemStateChanged(ItemEvent e) {
		// TODO Auto-generated method stub

	}

	public void valueChanged(ValueChangedEvent event) {
		try {
			UIRefPane corpRefPanel = ((TaskUI) m_billUI).getCorpPanel();
			if (corpRefPanel.getRefPK() != null && !"".equals(corpRefPanel.getRefPK().trim())) {
				UIRefPane deptRefPanel = ((TaskUI) m_billUI).getDeptPanel();
				String strWhere = "isnull(dr,0)=0";
				strWhere = strWhere + " and pk_corp = '" + corpRefPanel.getRefPK() + "'";
				if (deptRefPanel.getRefPK() != null && !"".equals(deptRefPanel.getRefPK().trim())) {
					strWhere = strWhere + " and pk_dept = '" + deptRefPanel.getRefPK() + "'";
				} else {
//					strWhere = strWhere + " and pk_dept is null";
				}
				((TaskUI) m_billUI).setInitStrWhere(strWhere);
				((TaskUI) m_billUI).initData();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
